* FIG 4: TRENDS IN OBWALDEN’S TAX BASE COMPARED TO THE REST OF SWITZERLAND

// NOTE: data needed for this do-file cannot be shared due to privacy reasons


version 16.1

clear all
cap log close 
cap clear matrix
set more off
cap set scheme mygraphs


*   LOAD & PREPARE THE DATA   
run "$mypathRR/Resources/prep_municipality_level_data.do"

// collapse (use weights when collapsing the data)
collapse $outcomes [aweight = n_taxpayers_tot_2005], by(year treated)

reshape wide $outcomes, i(year) j(treated)

foreach outcome in $outcomes  {
gen d_`outcome' = `outcome'1 - `outcome'0
}

// generate a trend
gen trend = year

foreach outcome in share300K reink  {
			reg d_`outcome' year if year < 2006 & year > 1994 
			predict tr`outcome', xb
			label var tr`outcome' "predicted cantonal time trend in `outcome'"
		}


label var d_share300K "Share of rich (in %)"
label var d_reink "Net income p.c. (in 1000 CHF)"

// plot graphs for each of the two outcomes
cd "$mypathRR/Results/"

format d_share300K %3.1f

foreach outcome in share300K reink  {
	
	if "`outcome'" == "share300K" {
	local figname "Fig_4a)-"
  }
  if "`outcome'" == "reink" {
	local figname "Fig_4b)-"
  }

  
graph twoway (connect d_`outcome' year if year >1994) (line tr`outcome' year if year >1994, lpattern(--) ) ///
, xline(2005.7, lcolor(red)) xline(2007.7, lcolor(green))  xtitle("") xlabel(, ang(45)) ///
 ytitle("`: variable label d_`outcome''") xsize(12) ysize(12) ///
legend(order(1 "difference T-C" 2 "pre-trend") row(2) ring(0) position(11) bmargin(small) size(small)) ///
name(did_`outcome', replace)
	graph export "`figname'did_C-T_`outcome'_with_trend_wght.pdf", replace	
}

						* * * * *  E N D  * * * * * * 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
